#include <windows.h>		// Header File For Windows
#include <gl\gl.h>			// Header File For The OpenGL32 Library
#include <gl\glu.h>			// Header File For The GLu32 Library
#include <gl\glaux.h>		// Header File For The Glaux Library

class picture
{
	public:
		GLfloat	xrot;				// X Rotation ( NEW )
		GLfloat	yrot;				// Y Rotation ( NEW )
		GLfloat	zrot;				// Z Rotation ( NEW )
		GLuint texture[2];			// Storage For two textures

	public:

		picture(){}

/************ LOAD BITMAP **********************************/
	AUX_RGBImageRec *LoadBMP(char *Filename)					// Loads A Bitmap Image
	{
		FILE *File=NULL;							// File Handle

		if (!Filename)								// Make Sure A Filename Was Given
		{
			return NULL;							// If Not Return NULL
		}

		File=fopen(Filename,"r");						// Check To See If The File Exists

		if (File)								// Does The File Exist?
		{
			fclose(File);							// Close The Handle
			return auxDIBImageLoad(Filename);				// Load The Bitmap And Return A Pointer
		}
		return NULL;								// If Load Failed Return NULL
	}

/************* LoadGLTextures *****************************/
// Load Bitmaps And Convert To Textures
	GLvoid LoadGLTextures()									// Load Bitmaps And Convert To Textures
	{
		AUX_RGBImageRec *TextureImage[2];

		memset(TextureImage,0,sizeof(void *)*2);				// Set The Pointer To NULL

		//Load images
		
		//This is where loadBMP should be used
		TextureImage[0]=LoadBMP("C:/Documents and Settings/Dominique/My Documents/Visual Studio 2005/Projects/webCube/webCube/logo.bmp");
		TextureImage[1]=LoadBMP("C:/Documents and Settings/Dominique/My Documents/Visual Studio 2005/Projects/webCube/webCube/logo.bmp");
		
		//TextureImage[0] = auxDIBImageLoad("C:/Documents and Settings/Dominique/My Documents/Visual Studio 2005/Projects/webCube/webCube/logo.bmp");
		//TextureImage[1] = auxDIBImageLoad("C:/Documents and Settings/Dominique/My Documents/Visual Studio 2005/Projects/webCube/webCube/computer1.bmp");
		
		//Check they opened correctly
		if(!TextureImage[0] || !TextureImage[1]) exit(1);
		
		//we want to build two textures, and we want the texture to be stored in texture[0], texture[1]
		glGenTextures(2, &texture[0]);

		// Loop Through All The Textures
		for(int loop=0; loop<2; loop++)	
		{
			// Build All The Textures
			glBindTexture(GL_TEXTURE_2D, texture[loop]);
			//The next two lines tell OpenGL what type of filtering to use when the image 
			//is larger (GL_TEXTURE_MAG_FILTER) or stretched on the screen than the original 
			//texture, or when it's smaller (GL_TEXTURE_MIN_FILTER) on the screen than the actual texture.
			glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);
			glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR);
			// Generate The Texture
			glTexImage2D(GL_TEXTURE_2D, 0, 3, TextureImage[loop]->sizeX, TextureImage[loop]->sizeY, 0, GL_RGB, GL_UNSIGNED_BYTE, TextureImage[loop]->data);
		}

		//The following lines of code check to see if the bitmap data we loaded to build our textures is using up ram. If it is, the ram is freed. 
		for(int loop=0; loop<2; loop++)
		{
	        if(TextureImage[loop])						// If Texture Exists
			{
				if(TextureImage[loop]->data)			// If Texture Image Exists
				{
					free(TextureImage[loop]->data);		// Free The Texture Image Memory
				}
				free(TextureImage[loop]);			// Free The Image Structure
			}
		}								// Return The Status
	}

////DRAW THE SCENE//////////

	GLvoid DrawGLSceneCube(GLvoid)
	{
		glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);		// Clear The Screen And The Depth Buffer
		glLoadIdentity();										// Reset The View
		glTranslatef(0.0f,0.0f,-5.0f);

		glBindTexture(GL_TEXTURE_2D, texture[0]);

		glBegin(GL_QUADS);
			// Front Face
			//glNormal3f( 0.0f, 0.0f, 1.0f);
			glTexCoord2f(0.0f, 1.0f); 
			glVertex3f(-1.0f,  1.0f,  0.0f);
			glTexCoord2f(1.0f, 1.0f); 
			glVertex3f( 1.0f,  1.0f,  0.0f);
			glTexCoord2f(1.0f, 0.0f); 
			glVertex3f( 1.0f, -1.0f,  0.0f);
			glTexCoord2f(0.0f, 0.0f); 
			glVertex3f(-1.0f, -1.0f,  0.0f);
		glEnd();
	}

	GLvoid DrawGLScene(GLvoid)
	{
		glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);		// Clear The Screen And The Depth Buffer
		glLoadIdentity();										// Reset The View
		
		for(int x = 0; x < 2; x++)
		{
			glBindTexture(GL_TEXTURE_2D, texture[x]);
			glBegin(GL_QUADS);

			glTexCoord2f(0.0f, 0.0f); glVertex3f(float(x), float(x), 0.0f);
			glTexCoord2f(1.0f, 0.0f); glVertex3f(float(x+1), float(x), 0.0f);
			glTexCoord2f(1.0f, 1.0f); glVertex3f(float(x+1), float(x+1), 0.0f);
			glTexCoord2f(0.0f, 1.0f); glVertex3f(float(x), float(x+1), 0.0f);
			glEnd();
		}
	}

//Depreciated!!!!!!!!!!!!!!!!!!!!
int draw_tiles(GLvoid)
{
	int map[10][10] = {{1, 1, 1, 1, 1, 1, 1, 1, 1, 1},
						   {1, 0, 0, 0, 0, 0, 0, 0, 0, 1},
						   {1, 0, 0, 0, 0, 0, 0, 0, 0, 1},
						   {1, 0, 0, 0, 0, 0, 0, 0, 0, 1},
						   {1, 0, 0, 0, 0, 0, 0, 0, 0, 1},
						   {1, 0, 0, 0, 0, 0, 0, 0, 0, 1},
						   {1, 0, 0, 0, 0, 0, 0, 0, 0, 1},
						   {1, 0, 0, 0, 0, 0, 0, 0, 0, 1},
						   {1, 0, 0, 0, 0, 0, 0, 0, 0, 1},
						   {1, 1, 1, 1, 1, 1, 1, 1, 1, 1}
						   };
  int tile;
	for (int y = 0; y < 10; y++)
  {
    for (int x = 0; x < 10; x++)
    {
		tile = map[y][x];
		glBindTexture(GL_TEXTURE_2D, texture[tile]);
								// Keep Going
		 glBegin(GL_QUADS);

    glTexCoord2f(0.0f, 0.0f); glVertex3f(float(x), float(y), 0.0f);
    glTexCoord2f(1.0f, 0.0f); glVertex3f(float(x + 1), float(y), 0.0f);
    glTexCoord2f(1.0f, 1.0f); glVertex3f(float(x + 1), float(y + 1), 0.0f);
    glTexCoord2f(0.0f, 1.0f); glVertex3f(float(x), float(y + 1), 0.0f);
    glEnd();

    }
  }
  return (1);
}

};